package com.swipemaster.levels;

import android.graphics.Canvas;

import com.swipemaster.elements.Circle;
import com.swipemaster.elements.Rectangle;
import com.swipemaster.game.GameSurface;

/** Type of level in which player's goal is to achieve finish. */
public class PuzzleLevel extends Level
{
	/** Destination element which player should touch to win. */
	protected final Rectangle finish;

	/** @param player Player circle.
	 * @param finish Finish rectangle.
	 * @param timeFor1Star Time to gain 1 star.
	 * @param timeFor2Stars Time to gain 2 stars.
	 * @param timeFor3Stars Time to gain 3 stars. */
	public PuzzleLevel(Circle player, Rectangle finish, double timeFor1Star, double timeFor2Stars, double timeFor3Stars)
	{
		super(player, 0, timeFor1Star, timeFor2Stars, timeFor3Stars);
		this.finish = finish;
	}

	@Override
	public void draw(Canvas canvas)
	{
		finish.draw(canvas);
		super.draw(canvas);
	}

	@Override
	public int getStars()
	{
		final double playingTime = GameSurface.level.getPlayingTime();
		if (playingTime < timeFor3Stars)
		{
			return 3;
		}
		if (playingTime < timeFor2Stars)
		{
			return 2;
		}
		if (playingTime < timeFor1Star)
		{
			return 1;
		}
		return 0;
	}

	@Override
	public boolean isLoser()
	{
		return isPlayerCollidingWithEnemy();
	}

	@Override
	public boolean isWinner()
	{
		return player.isCollisionWith(finish);
	}
}
